uniform extern texture gTex;
float timer = 0.0f;
float3 grayscale = { 0.2125f, 0.7154f, 0.0721f };
float total = 4.0f;

sampler TexS = sampler_state {
	Texture = <gTex>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = LINEAR;
	//AddressU  = WRAP;
    //AddressV  = WRAP;
};

struct OutputVS {
    float4 posH   : POSITION0;
	float2 Tex   : TEXCOORD0;
};


OutputVS FadeVS(float4 posL : POSITION0,float2 Tex: TEXCOORD0) {
    // Zero out our output.
	OutputVS outVS = (OutputVS)0;	
	// already transformed
	outVS.posH = posL;	
	outVS.Tex = Tex; 
    return outVS;
}

float4 FadePS(float2 Tex : TEXCOORD0) : COLOR {    
	float4 scaledColor = dot( (float3)tex2D( TexS, Tex ), grayscale );
	float diff = timer / total;
	float scale = 1.0 - diff;
	return tex2D(TexS,Tex) * scale + scaledColor*diff;              
}

technique FadeTech {
    pass P0 {
        vertexShader = compile vs_2_0 FadeVS();
        pixelShader  = compile ps_2_0 FadePS();
    }
}